package com.example.java8.timeapi;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.TemporalAdjusters;

public class TemporalAdjustersTest {
    public static void main(String[] args) {
        adjus();
    }

    public static void adjus() {
        LocalDateTime localDateTime = LocalDateTime.now();

        //获取下一个周日
        LocalDateTime localDateTime1 = localDateTime.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));
        System.out.println(localDateTime1);

        //获取下一个工作日
        localDateTime.with((o) -> {
            LocalDateTime ldt2 = (LocalDateTime) o;
            DayOfWeek dayOfWeek = ldt2.getDayOfWeek();
            if (dayOfWeek.equals(DayOfWeek.FRIDAY)) {
                return ldt2.plusDays(3);
            } else if (dayOfWeek.equals(DayOfWeek.SUNDAY)) {
                return ldt2.plusDays(2);
            } else {
                return ldt2.plusDays(1);
            }
        });
    }
}
